package Model.Core.Impl;

import Factory.Entities.TransitionFactory;
import Factory.Tip.TipsFactory;
import Model.Core.IAchievableState;
import Model.Core.IMachineStateElement;
import Model.Core.IOriginatorState;
import Model.Core.Tip.Tip;
import Model.Core.Tip.TipMoment;
import Model.Core.Tip.TipType;
import Model.Draw.Entities.TransitionDraw;
import Model.Draw.Events.ManifestStateDoneListener;
import Model.Draw.IMachineStateDraw;
import java.util.List;

/**
 * Projeto de TCC: Editor de Diagramas de comunicação BlueJ
 * @author Jose
 */
public class Transition implements IMachineStateElement {

    private IOriginatorState originatorState;
    private IAchievableState achievableState;
    private TransitionDraw transitionDraw;
    private List<Tip> tips;
    private TransitionFactory transitionFactory;

    public Transition() {
        tips = TipsFactory.createTrasitionTips();
        transitionFactory = new TransitionFactory();
    }

    
    @Override
    public IMachineStateDraw getDraw() {
        return transitionDraw;
    }

    @Override
    public void setDraw(IMachineStateDraw draw) {
        transitionDraw = (TransitionDraw) draw;
    }
    
    @Override
    public void manifestGraphically(Object sourceElement, Object targetElement) {
       transitionFactory.createStateGraphicalManifest(this, sourceElement, targetElement);
    }

    @Override
    public void addGraphicalManifestListener(ManifestStateDoneListener listener) {
        transitionFactory.addListener(listener);
    }

    @Override
    public void removeGraphicalManifestListener(ManifestStateDoneListener listener) {
        transitionFactory.removeListener(listener);
    }

    @Override
    public Tip findTipBy(TipType type, TipMoment moment) {
        for (Tip tip : tips) {
            if (tip.getType() == type && tip.getMoment() == moment) {
                return tip;
            }
        }
        return null;
    }

    public IAchievableState getAchievableState() {
        return achievableState;
    }

    public void setAchievableState(IAchievableState achievableState) {
        this.achievableState = achievableState;
    }

    public IOriginatorState getOriginatorState() {
        return originatorState;
    }

    public void setOriginatorState(IOriginatorState originatorState) {
        this.originatorState = originatorState;
    }
}